<%@page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.learn.User"%>
<%@page import="java.util.List"%>
<%@page import="com.learn.UserDAO"%>

<html>
<%

ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
UserDAO userDAO = context.getBean(UserDAO.class);
String loginName = request.getParameter("loginName");
String pwd = request.getParameter("password");

if(loginName!=null &&pwd !=null){
	boolean valid = userDAO.isvalidUser(loginName, pwd);
	if(valid){
		List<User> users = userDAO.getAllUsers();

		if(users!=null){
			%>
			<table border="1">
			<tr>
				<td>S.No</td>
				<td>FirstName</td>
				<td>LastName</td>
				<td>Email Id</td>
				<td>Mobile No</td>
				<td>DOB</td>
			</tr>
			<%
			int i =0;
			for(int j=0;j<users.size();j++){
				i++;
				User user = users.get(j);
				%>
				<tr>
					<td><%=i%></td>
					<td><%=user.getFirstName() %></td>
					<td><%=user.getLastName() %></td>
					<td><%=user.getEmailId() %></td>
					<td><%=user.getPhoneNo() %></td>
					<td><%=user.getDob() %></td>
				</tr>
				<%
			}
			%>
			</table>
		<%	
		}
	}else{
		response.sendRedirect("index.jsp");
	}
}else{
	response.sendRedirect("index.jsp");
}

%>
<body>

</body>
</html>
